﻿using Travel.Data.Dtos;
using Travel.Data.Inputs;
using Travel.Data;
using Microsoft.AspNetCore.Mvc;
using Travel.Service.User;
using Travel.API.Filters;
using Travel.Data.Consts;

namespace Travel.API.Controller
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class RoleAuthorityController:BaseController
    {

        private readonly IRoleAuthorityService _roleAuthorityService;

        public RoleAuthorityController(IRoleAuthorityService roleAuthorityService)
        {
            _roleAuthorityService = roleAuthorityService;
        }

        /// <summary>
        /// 为角色分配权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public   async Task<Results<int>> DistributeAuthority([FromBody]RoleAuthorityInput input) { 
        
            return await _roleAuthorityService.DistributeAuthority(input);
        }
        /// <summary>
        /// 获取左边菜单栏
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<List<LeftMenuDto>>> GetLeftMenuByRoleId()
        {
            return await _roleAuthorityService.GetLeftMenuByRoleId(CurrentRoleId);

        }

        /// <summary>
        /// 获取角色权限列表
        /// </summary>
        /// <param name="loginRoleId"></param>
        /// <returns></returns>
        [HttpGet("{loginRoleId}")]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<List<AuthorityDto>>> GetAuthoritiesByRoleId([FromBody] long loginRoleId) { 
        
            return await _roleAuthorityService.GetAuthoritiesByRoleId(loginRoleId);
        }
    }
}
